import Mock from 'mockjs'
// mock用户信息数据
let userList = [
	{
     userId: 1,
     avatar:'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
     username: 'admin',
     password: '111111',
     desc: '平台管理员',
     roles: ['平台管理员'],
     buttons: ['cuser.detail'],
     routes: ['home'],
     token: 'Admin Token',
        },
	{
		 userId: 2,
     avatar:'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
     username: 'system',
     password: '111111',
     desc: '系统管理员',
     roles: ['系统管理员'],
     buttons: ['cuser.detail', 'cuser.user'],
     routes: ['home'],
     token: 'System Token',
	}
]
// 定义用户登录接口
Mock.mock('/api/user/login', 'post', (options) => {
     // const body = JSON.parse(options.body)
     const body = JSON.parse(options.body)
     const checkUser = userList.find(
          (item) => item.username === body.username && item.password ===body.password
     )
     console.log('checkUser', checkUser);
     if (!checkUser) {
          return {
               code: 201,
               data: {
                    message:'账号或密码错误'
               }
          }
     }  
     console.log('token',checkUser.token);
     
     
	return {
          code: 200,
          data: {
               message: '登陆成功',
               token:checkUser.token

               
          }
		
	}
},
// 定义获取用户信息接口
     Mock.mock('/api/user/info', 'get', (options) => {
     console.log(options);
     
		return {
			status: 200,
			message:'获取用户信息成功'
		}
	})

)